package com.zklh.leetcode.other.problem12;



/**
 * @author 坐看落花
 * @version 1.0
 * @date 2023/5/9 17:36
 */
public class Solution {
    public String intToRoman(int num) {
        char[] romanNumerals = {'I', 'V', 'X', 'L', 'C', 'D' ,'M'};
        int[] romanNums = {1, 5, 10, 50, 100, 500, 1000};

        int remainder = num;
        StringBuilder result = new StringBuilder();

        for (int i = 3; i >= 0; i--) {
            int quotient = remainder / romanNums[2 * i];
            remainder = remainder % romanNums[2 * i];
            if (quotient == 0) {
                continue;
            }
            if (quotient == 9) {
                result.append(romanNumerals[2 * i]).append(romanNumerals[2 * i + 2]);
            } else if (quotient >= 5){
                result.append(romanNumerals[2 * i + 1]);
                for (int j = 0; j < quotient - 5; j++) {
                    result.append(romanNumerals[2 * i]);
                }
            } else if (quotient == 4) {
                result.append(romanNumerals[2 * i]).append(romanNumerals[2 * i + 1]);
            } else {
                for (int j = 0; j < quotient; j++) {
                    result.append(romanNumerals[2 * i]);
                }
            }
        }
        return result.toString();
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.intToRoman(3));
        System.out.println(solution.intToRoman(4));
        System.out.println(solution.intToRoman(9));
        System.out.println(solution.intToRoman(58));
        System.out.println(solution.intToRoman(1994));
        System.out.println(Math.pow(10,3));
    }
}
